package com.balance.anole.erp.component;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

public class TextWithPopupButton extends Composite {

	private Text text;

	private Button button;

	public Text getText(){
		return this.text;
	}

	public void setEditable(boolean editable){
		this.text.setEditable(editable);
	}

	public  TextWithPopupButton(Composite parent, int style, final Dialog selector) {
		super(parent, style);

		final FormLayout layout = new FormLayout();
		this.setLayout(layout);
		text = new Text(this, SWT.BORDER);
		final FormData fd_text = new FormData();
		fd_text.bottom = new FormAttachment(100, -1);
		fd_text.top = new FormAttachment(0, 1);
		fd_text.left = new FormAttachment(0, 0);
		text.setLayoutData(fd_text);

		button = new Button(this, SWT.NONE);
		fd_text.right = new FormAttachment(button, -30, SWT.RIGHT);
		final FormData fd_button = new FormData();
		fd_button.top = new FormAttachment(0, 1);
		fd_button.bottom = new FormAttachment(100, -1);
		fd_button.left = new FormAttachment(100, -31);
		fd_button.right = new FormAttachment(100, -1);
		button.setLayoutData(fd_button);
		button.setText("...");

		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				selector.open();
			}
		});

	}

}
